#!/usr/bin/env python3
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

import sys
import lzma
import gc

import psutil

filename = sys.argv[1]

with lzma.open(filename, "r") as fileh:
    fixture = fileh.read()

proc = psutil.Process()

lib_name = sys.argv[2]
if lib_name == "json":
    from json import dumps, loads
elif lib_name == "orjson":
    from orjson import dumps, loads
elif lib_name == "rapidjson":
    from rapidjson import dumps, loads
elif lib_name == "simplejson":
    from simplejson import dumps, loads
elif lib_name == "ujson":
    from ujson import dumps, loads
else:
    raise NotImplementedError

gc.collect()

mem_before = proc.memory_info().rss

for _ in range(100):
    val = loads(fixture)

mem_after = proc.memory_info().rss

mem_diff = mem_after - mem_before

from json import loads as json_loads

correct = 1 if (json_loads(fixture) == json_loads(dumps(loads(fixture)))) else 0

print(f"{mem_before},{mem_diff},{correct}")
